package com.obas.access.business.service.impl;

import java.util.List;

import com.ease.common.vo.MapParameter;
import com.ease.platform.access.service.impl.AbstractNamespaceAccessServiceImpl;
import com.obas.access.business.service.BusinessScenarioAccessService;
import com.obas.model.business.BusinessScenario;
import com.obas.model.business.criteria.BusinessScenarioCriteria;

public class BusinessScenarioAccessServiceImpl extends AbstractNamespaceAccessServiceImpl<BusinessScenario> implements BusinessScenarioAccessService {

	static final class Statement {
		public static final String associateBusinessRepository = "associateBusinessRepository";
		public static final String disassociateBusinessRepository = "disassociateBusinessRepository";
	}

	public List<BusinessScenario> findByBusinessRepositoryId(long businessRepositoryId) {
		BusinessScenarioCriteria parameter = new BusinessScenarioCriteria();
		parameter.setBusinessRepositoryId(businessRepositoryId);
		return this.find(parameter);
	}

	public BusinessScenario createEntity(BusinessScenario businessScenario, long businessRepositoryId) {
		businessScenario = this.create(businessScenario);
		if (businessRepositoryId > 0) {
			associateBusinessRepository(businessScenario.getId(), businessRepositoryId);
		}
		return businessScenario;
	}

	public void associateBusinessRepository(long businessScenarioId, long businessRepositoryId) {
		MapParameter parameter = new MapParameter();
		parameter.put("businessScenarioId", businessScenarioId);
		parameter.put("businessRepositoryId", businessRepositoryId);
		this.update(Statement.associateBusinessRepository, parameter);
	}

	public void disassociateBusinessRepository(long businessScenarioId, long businessRepositoryId) {
		MapParameter parameter = new MapParameter();
		parameter.put("businessScenarioId", businessScenarioId);
		parameter.put("businessRepositoryId", businessRepositoryId);
		this.remove(Statement.disassociateBusinessRepository, parameter);
	}

}
